package com.un.core.common;
import java.io.Serial;
import java.util.HashMap;

/**
 * @Author xingjian
 * @Date 2023-01-12
 **/
public class R extends HashMap<String,Object> {

    @Serial
    private static final long serialVersionUID = 1L;

    private int code;
    private String msg;
    private Object data;

    public static final String CODE_TAG = "code";

    public static final String MSG_TAG = "msg";

    public static final String DATA_TAG = "data";

    public R() {
    }

    public R(int code, String msg) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        this.code=code;
        this.msg=msg;
    }
    public R(int code, String msg, Object data) {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        this.code=code;
        this.msg=msg;
        if (!(data==null)) {
            super.put(DATA_TAG, data);
            this.data=data;
        }
    }
    public static R success() {
        return R.success("操作成功!");
    }

    public static R success(String msg) {
        return R.success(msg, null);
    }

    public static R success(Object data) {
        return R.success("操作成功!", data);
    }


    public static R success(String msg, Object data) {
        return new R(200, msg, data);
    }

    public static R error() {
        return R.error("操作失败!");
    }

    public static R error(String msg) {
        return R.error(msg, null);
    }

    public static R error(String msg, Object data) {
        return new R(500, msg, data);
    }

    public static R error(int code, String msg) {
        return new R(code, msg, null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}




